<template>
  <el-table :data="tableData" stripe style="width: 100%">
    <el-table-column prop="date" label="日期" width="180"> </el-table-column>
    <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
    <el-table-column label="性别" width="180">
      <!-- 作用域插槽 -->
      <!-- 将当前这一行的数据对象,传递过来 -->
      <!-- slot-scope="scope" Vue 2.6的新语法 -->
      <template v-slot="scope">
        {{ handleGender(scope.row.gender) }}
      </template>
    </el-table-column>
    <el-table-column prop="address" label="地址"> </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: 'VueElementApp',

  data () {
    return {
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        gender: 1,
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        gender: 1,

        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        gender: 0,
        address: '上海市普陀区金沙江路 1519 弄'
      }]
    }
  },

  mounted () {},

  methods: {
    // 优雅的处理方式
    // gender:0或1,未来如果扩张,只需要添加genderObj的属性即可
    handleGender (gender) {
      const genderObj = {
        0: '男',
        1: '女',
        2: '妖'
      }
      return genderObj[gender]
    }
  }
}
</script>

<style lang="scss" scoped></style>
